"""
*** 街道的每月排查数据,分图显示，柱状图和折线图 ***
"""

import matplotlib.pyplot as plt
import numpy as np

months = ["一月", "二月", "三月", "四月", "五月", "六月", "七月"]
y = [
    [81, 81, 76, 77, 138, 163, 124],  # 凌水
    [26, 25, 25, 26, 86, 66, 93],  # 龙王塘
    [108, 106, 93, 86, 91, 56, 108],  # 七贤岭
]
labels = ["凌水", "龙王塘", "七贤岭"]
colors = ["red", "blue", "green", "yellow", "purple"]

# 创建一个包含1行3列子图的画布
fig, axs = plt.subplots(3)  # 三行一列
# fig, axs = plt.subplots(1, 3) #一行三列

for i in range(len(labels)):
    # plt.subplot(3, 2, i + 1)
    # plt.bar(months, y[i], label=labels[i], color=colors[i])
    # row = 1  # 计算子图所在的行
    # col = i  # 计算子图所在的列
    axs[i].bar(months, y[i], label=labels[i], color=colors[i])
    axs[i].legend()
    # axs[i].set_xlabel("月份")
    axs[i].set_ylabel("数量")
    axs[i].set_ylim(0, max(y[i]) + 50)
    axs[i].grid(True)
    # 绘制折线
    axs[i].plot(months, y[i], color=colors[i])
    # axs[i].set_title(labels[i])

    # 在每个柱子上显示数值
    for j, v in enumerate(y[i]):
        # 在条形上方添加文本
        axs[i].text(j, v + 0.5, str(v), ha="center", va="bottom")

# axs[2, 1].clear()  # 清除最后一个子图，因为我们不需要它
# axs[2, 1].set_axis_off()
# axs[2, 1].set_xticks([])
# axs[2, 1].set_yticks([])
# axs[2, 1].set_title("")

# 设置中文用楷体
plt.rcParams["font.sans-serif"] = ["KaiTi"]

# 添加总标题
plt.suptitle("1-7月各街道矛盾纠纷排查情况", fontsize=24)
# 显示图形
plt.show()
